/* 
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.shanekjohnson.cmis.client.atompub.model
{
	import mx.collections.ArrayCollection;
	
	public class Document
	{
		private namespace app = "http://www.w3.org/2007/app";
		private namespace atom = "http://www.w3.org/2005/Atom";
		private namespace cmis = "http://docs.oasis-open.org/ns/cmis/core/200908/";
		private namespace cmisra = "http://docs.oasis-open.org/ns/cmis/restatom/200908/";
		
		use namespace app;
        use namespace atom;
        use namespace cmis;
        use namespace cmisra;
		
		public var name:String;
		public var fileName:String;
		public var url:String;
		
		[Bindable] public var checkedOut:Boolean;
		
		[Bindable] public var properties:ArrayCollection;
		
		public function Document()
		{
			properties = new ArrayCollection();
		}
		
		public static function getDocument(d:XML):Document 
		{
			var doc:Document = new Document();
			
			doc.name = d.title;
			doc.fileName = d.object.properties.propertyString.(@propertyDefinitionId=='cmis:contentStreamFileName').value;
			doc.url = d.content.@src;
			
			var co:String = d.object.properties.propertyBoolean.(@propertyDefinitionId=='cmis:isVersionSeriesCheckedOut').value;
			
			if (co == "true")
				doc.checkedOut = true;
			else
				doc.checkedOut = false;
			
			for each(var p:XML in d.object.properties.children()) 
			{
				var prop:Property = new Property();
			
				prop.name = p.@propertyDefinitionId;
				prop.value = p.value;
				
				doc.properties.addItem(prop);
			}
			
			return doc;
		}

	}
	
}